/**
 * @param {number} n
 * @param {number[][]} roads
 * @return {number}
 */
 var maximumImportance = function(n, roads) {
  const ingree = {}
  for(const [x, y] of roads) {
    ingree[x] = ~~ingree[x] + 1
    ingree[y] = ~~ingree[y] + 1
  }
  const ks = Object.keys(ingree).sort((a,b) => ingree[b] - ingree[a])
  const mp = new Map()
  for(let i = n, j = 0; i>=1; i--, j++) {
    mp.set(ks[j], i)
  }
  let ans = 0
  for(const [x, y] of roads) {
    ans += mp.get(x+'') + mp.get(y+'')
  }
  return ans
};